import http from '@/utils/request'
/**
 * 获取登陆信息
 * @param {*} mobile
 * @param {*} code
 * @returns
 */
export const reqLogin = (mobile, code) => http({
  url: '/v1_0/authorizations',
  method: 'post',
  data: {
    mobile,
    code
  }
})

/**
 * 关注用户
 * @param {*} userId 作者的id
 */
export const reqFollowUser = (userId) => {
  return http({
    method: 'post',
    url: '/v1_0/user/followings',
    data: {
      target: userId
    }
  })
}
/**
 * 取消关注用户
 * @param {*} userId 作者的id
 */
export const reqUnFollowUser = (userId) => {
  return http({
    method: 'delete',
    url: '/v1_0/user/followings/' + userId
  })
}

/**
 * 获取文章的评论
 * @param {*} articleId 文章编号
 * @param {*} offset 获取评论数据的偏移量，值为评论id，表示从此id的数据向后取，不传表示从第一页开始读取数据
 */
export const reqGetComments = (articleId, offset) => {
  return http({
    method: 'get',
    url: '/v1_0/comments',
    params: {
      type: 'a', // a表示对文章的评论 ,c表示对评论的回复
      source: articleId,
      offset
    }
  })
}
/**
 * 使用refresh_token刷新token
 * @param {*} refresh_token
 * @returns
 */
// eslint-disable-next-line camelcase
export const reqGetNewToken = (refresh_token) => http({
  url: '/v1_0/authorizations',
  method: 'put',
  headers: {
    // eslint-disable-next-line camelcase
    Authorization: 'Bearer ' + refresh_token
  }
})
/**
 * 获取用户个人信息 (用于个人中心页的渲染数据)
 */
export const reqGetUserInfo = () => {
  return http({
    method: 'get',
    url: '/v1_0/user'
  })
}

/**
 * 获取用户个人信息(编辑页)
 */
export const reqGetProfile = () => {
  return http({
    method: 'get',
    url: '/v1_0/user/profile'
  })
}

/**
 * 修改用户个人信息
 * obj {
 *   name: 昵称,
 *   birthday: 生日
 *   gender: 性别
 * }
 */
export const reqUpdateUserInfo = (obj) => {
  return http({
    method: 'patch',
    url: '/v1_0/user/profile',
    data: obj
  })
}

/**
 * 修改用户头像
 * @param {*} formData 收集文件对象的formData
 */
export const reqUpdatePhoto = (formData) => {
  return http({
    method: 'patch',
    url: '/v1_0/user/photo',
    data: formData
  })
}
